﻿using System.ComponentModel.Composition;
using IntoNails.Infrastructure.InteractionRequests;
using IntoNails.Infrastructure.ViewModels;
using IntoNails.Models;
using IntoNails.Modules.CategoryManagement.EventAggregators;
using Microsoft.Practices.Prism.Commands;
using Microsoft.Practices.Prism.Events;
using Microsoft.Practices.Prism.ViewModel;

namespace IntoNails.Modules.CategoryManagement.ViewModels
{
    [Export(typeof(ICategoryWorkspaceViewModel))]
    [PartCreationPolicy(CreationPolicy.NonShared)]
    public partial class CategoryWorkspaceViewModel : NotificationObject, ICategoryWorkspaceViewModel
    {
        #region Fields

        private readonly IEventAggregator _eventAggregator;

        #endregion

        #region Constructors

        [ImportingConstructor]
        public CategoryWorkspaceViewModel(IEventAggregator eventAggregator)
        {
            this._eventAggregator = eventAggregator;
            this._eventAggregator.GetEvent<CreateNewCategoryEventAggregator>().Subscribe(OnCreateNewCategoryEventSubscribed, ThreadOption.PublisherThread);
            this._eventAggregator.GetEvent<RenameCategoryEventAggregator>().Subscribe(OnRenameCategoryEventSubscribed, ThreadOption.UIThread);
            this._eventAggregator.GetEvent<DeleteCategoryEventAggregator>().Subscribe(OnDeleteCategoryEventSubscribed, ThreadOption.UIThread);

            this._eventAggregator.GetEvent<CreateNewServiceEventAggregator>().Subscribe(OnCreateNewServiceEventSubscribed, ThreadOption.PublisherThread);
            this._eventAggregator.GetEvent<EditServiceEventAggregator>().Subscribe(OnEditServiceEventSubscribed, ThreadOption.UIThread);
            this._eventAggregator.GetEvent<DeleteServiceEventAggregator>().Subscribe(OnDeleteServiceEventSubscribed, ThreadOption.UIThread);

            #region Init Left Region

            this.PopulateCategoryTree();

            #endregion

            this.CategoryTreeNodeSelectedCommand = new DelegateCommand<TreeNodeViewModel>(this.OnCategoryTreeNodeSelected);

            this.CreateNewCategoryNotification = new GenericInteractionRequest<Category>();
            this.CreateNewServiceNotification = new GenericInteractionRequest<Service>();
            this.ShowMessageBox = new GenericInteractionRequest<MessageBoxContext>();
        }

        #endregion
        
        #region Command Action Handlers
        
        #endregion

        #region Interaction Requests

        public GenericInteractionRequest<Category> CreateNewCategoryNotification { get; private set; }

        public GenericInteractionRequest<Service> CreateNewServiceNotification { get; private set; } 

        public GenericInteractionRequest<MessageBoxContext> ShowMessageBox { get; private set; }

        #endregion

        #region Event Handlers

        

        #endregion
    }
}
